import tkinter as tk
from views import AboutFrame, ChangetFrame, SelectFrame, InsertFrame, DelFrame


class Main:
    def __init__(self, master):
        self.root = master
        self.root.title('学生信息管理系统')
        self.root.geometry('600x400')
        self.show_sum()
        self.create_page()

    # 菜单
    def create_page(self):
        menubar = tk.Menu(self.root)
        menubar.add_command(label='录入', command=self.show_insert)
        menubar.add_command(label='查询', command=self.show_select)
        menubar.add_command(label='删除', command=self.show_del)
        menubar.add_command(label='修改', command=self.show_change)
        menubar.add_command(label='关于', command=self.show_about)
        self.root['menu'] = menubar

    # 创建每个页面
    def show_sum(self):
        self.about_fram = AboutFrame(self.root)
        self.change_fram = ChangetFrame(self.root)
        self.select_fram = SelectFrame(self.root)
        self.insert_fram = InsertFrame(self.root)
        self.del_fram = DelFrame(self.root)

    # 关于页面
    def show_about(self):
        self.about_fram.pack()
        # 隐藏指定页
        self.change_fram.pack_forget()
        self.select_fram.pack_forget()
        self.insert_fram.pack_forget()
        self.del_fram.pack_forget()

    # 修改页面
    def show_change(self):
        self.change_fram.pack()
        # 隐藏指定页
        self.about_fram.pack_forget()
        self.select_fram.pack_forget()
        self.insert_fram.pack_forget()
        self.del_fram.pack_forget()

    # 查询界面
    def show_select(self):
        # 每次切回该页面都清空一下表格中的数据
        self.select_fram.show_clear()
        self.select_fram.pack()
        # 隐藏无关界面
        self.change_fram.pack_forget()
        self.about_fram.pack_forget()
        self.insert_fram.pack_forget()
        self.del_fram.pack_forget()

    # 插入界面
    def show_insert(self):
        self.insert_fram.pack()

        # 隐藏无关界面
        self.change_fram.pack_forget()
        self.about_fram.pack_forget()
        self.select_fram.pack_forget()
        self.del_fram.pack_forget()

    # 删除页面
    def show_del(self):
        self.del_fram.pack()
        # 隐藏无关界面
        self.change_fram.pack_forget()
        self.about_fram.pack_forget()
        self.select_fram.pack_forget()
        self.insert_fram.pack_forget()



if __name__ == '__main__':
    root = tk.Tk()
    Main(master=root)
    root.mainloop()
